package com.group.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.group.pojo.Job;
import com.group.pojo.JobData;
import com.group.service.JobDataService;
import com.group.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/job-data")
@Api
@CrossOrigin
public class JobDataController {

    @Autowired
    JobDataService jobDataService;

    @Autowired
    private ObjectMapper jackson;

    @ApiOperation(value = "根据招聘id获取应聘人资料")
    @PostMapping("getJobData1")
    public R getJobData1(@RequestBody Map<String, Object> map) throws JsonProcessingException {
        JobData job = jackson.readValue(jackson.writeValueAsString(map.get("jobdata")), JobData.class);
        Integer pageNo = (Integer) map.get("pageno");
        Integer pageSize = (Integer) map.get("pagesize");
        PageInfo<JobData> data = jobDataService.getJobData1(job, pageNo, pageSize);
        return R.ok().data("pageInfo", data);
    }

    @ApiOperation(value = "条件查询信息")
    @PostMapping
    public R findJobDataByLike1() {

        return R.ok();
    }

    @ApiOperation(value = "更新应聘人资料信息")
    @PostMapping("updateJobDataState1")
    public R updateJobDataState1(@RequestBody JobData jobData) {
        boolean flag = jobDataService.updateJobDataState1(jobData);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation(value = "根据用户id获取应聘人资料")
    @PostMapping("getJobDataByUserId1")
    public R getJobDataByUserId1(@RequestBody Map<String, Object> map) throws JsonProcessingException {
        JobData job = jackson.readValue(jackson.writeValueAsString(map.get("jobdata")), JobData.class);
        Integer pageNo = (Integer) map.get("pageno");
        Integer pageSize = (Integer) map.get("pagesize");
        PageInfo<JobData> data = jobDataService.getJobDataByUserId1(job, pageNo, pageSize);
        return R.ok().data("pageInfo", data);
    }

    @ApiOperation(value = "添加应聘人资料")
    @PostMapping("addJobData1")
    public R addJobData1(@RequestBody JobData jobData) {
        boolean flag = jobDataService.addJobData1(jobData);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation(value = "删除应聘人资料")
    @DeleteMapping("{id}")
    public R deleteJobData1(@PathVariable("id") int id) {
        boolean flag = jobDataService.deleteJobData1(id);
        return flag ? R.ok() : R.error();
    }

    @ApiOperation(value = "批量删除应聘人")
    @DeleteMapping("deleteJobDataBatch1")
    public R deleteJobDataBatch1(String batch) {
        String[] list = batch.split(",");
        boolean flag = jobDataService.deleteJobDataBatch1(list);
        return flag ? R.ok() : R.error();
    }
}

